﻿using CQIE.JonJack.SplLibraryService._IPublicService;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

namespace CQIE.JonJack.SplLibraryManagementSystem.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PublicController : ControllerBase
    {
        private readonly IPublicService publicService;

        public PublicController(IPublicService publicService)
        {
            this.publicService = publicService;
        }


        public record UserModel(string schoolNumber,string passWord);
        [HttpPost]
        public ActionResult<string> userLogin([FromBody]UserModel user)
        {
            return Ok(publicService.login(user.schoolNumber,user.passWord));
        }


        [HttpGet]
        public ActionResult<string> getAllBooks()
        {
            return Ok(publicService.getAllBooksAsync());
        }
        public record NUser(string name,string schoolNumber,string passWord,string confirmPassWord);
        [HttpPost]
        public ActionResult userRegister([FromBody]NUser user) 
        {
            string jsonString = JsonConvert.SerializeObject(user);
            return Ok(publicService.userRegister(jsonString));
        }
    }
}
